/* 
 * Copyright (C) 2008 anphoralhrod.blogspot.com
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * SimpleLinkLabel.java
 *
 * Created on 12 de julio de 2008, 0:44
 */

package SimpleControl;

import Util.*;
import java.awt.Color;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;

/**
 *
 * @author  fran
 */
public class SimpleLinkLabel extends JLabel {

    URI link = null;
    /** Creates new form BeanForm */
    public SimpleLinkLabel()
    {
        super();
        inic();
    }

    /**
     * Inicializa los valores de la SimpleLinkLabel
     */
    private void inic()
    {
        this.setForeground(Color.BLUE);
        this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.HAND_CURSOR));
        this.addMouseListener(new java.awt.event.MouseAdapter() {
            @Override
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mouseClick(evt);
            }
        });
    }

    private void mouseClick(java.awt.event.MouseEvent evt) {                                     
        // TODO add your handling code here:
        if (link != null)
            if (Util.launchURL(link.toString()))
                this.setForeground(Color.RED);
    }
    
    public void setLink(String link)
    {
        try {
            this.link = new URI(link);
        } catch (URISyntaxException ex) {
            Logger.getLogger(SimpleLinkLabel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public String getLink()
    {
        return (link != null) ? link.toString() : "";
    }

}
